<template>
  <!-- 顶部 -->
  <div class="top">
    <div class="cen">
      <img
        src="https://imagev2.xmcdn.com/storages/3777-audiofreehighqps/49/07/GMCoOSMH3Kb7AAAPQgH_va2X.png"
        alt=""
      />
      <div class="a">打开APP</div>
    </div>
    <router-link to="/search">
      <van-search
        class="search"
        v-model="value"
        placeholder="请输入搜索关键词"
      />
    </router-link>
  </div>
  <div class="cqi"></div>
  <!-- 轮播图 -->
  <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
    <van-swipe-item>
      <img
        src="https://fdfs.xmcdn.com/storages/c380-audiofreehighqps/09/66/GKwRIUEIcGNVAAH7LAIvlG7e.jpg"
        alt=""
      />
    </van-swipe-item>
    <van-swipe-item>
      <img
        src="https://fdfs.xmcdn.com/storages/3b9a-audiofreehighqps/1E/01/GKwRIJEHZNtuAAGIJQHc8x8h.jpg"
        alt=""
      />
    </van-swipe-item>
    <van-swipe-item>
      <img
        src="https://fdfs.xmcdn.com/storages/3994-audiofreehighqps/E1/BB/GMCoOSUIsiylAAGzIgJJ2Sf5.jpg"
        alt=""
      />
    </van-swipe-item>
  </van-swipe>
  <!-- 排行榜 分类 听单 -->
  <div class="pft">
    <router-link to="/rank"
      ><div>
        <img
          src="https://fdfs.xmcdn.com/group56/M09/3B/BD/wKgLgFyQujLCAVYRAAAuwA7DZMg198.png"
          alt=""
        />
        <p>排行榜</p>
      </div></router-link
    >
    <router-link to="/category"
      ><div>
        <img
          src="https://fdfs.xmcdn.com/group60/M02/18/F4/wKgLeVziZxHRlc-lAAAO9ZkPU-I489.png"
          alt=""
        />
        <p>分类</p>
      </div></router-link
    >
    <router-link to="/listen"
      ><div>
        <img
          src="https://fdfs.xmcdn.com/group57/M0A/3B/D0/wKgLgVyQuqWRZsJtAAAnr8tg4rs307.png"
          alt=""
        />
        <p>听单</p>
      </div></router-link
    >
  </div>
  <!-- 大图 -->
  <div class="big">
    <img
      src="	https://imagev2.xmcdn.com/group61/M0A/CD/B2/wKgMZl0W1legiUgkAACPrBBFcJ4381.png"
      alt=""
    />
  </div>
  <!-- 新人必听 -->
  <div class="xrbt">新人必听</div>
  <div class="new">
    <div
      @click="toDetail(item.albumId)"
      class="new-item"
      v-for="(item, index) in newArr"
      :key="item.albumId"
    >
      <div class="new-item-img">
        <img :src="'https://imagev2.xmcdn.com/' + item.albumCoverPath" alt="" />
        <div class="new-item-text">
          <van-icon name="play-circle-o" /> {{ item.albumPlayCount }}
        </div>
      </div>
      <p class="title">{{ item.intro }}</p>
    </div>
  </div>
  <!-- 限时免费 -->
  <div class="xrbt">
    限时免费&nbsp;&nbsp;
    <van-count-down :time="time">
      <template #default="timeData">
        <span class="block">{{ timeData.hours }}</span>
        <span class="colon">:</span>
        <span class="block">{{ timeData.minutes }}</span>
        <span class="colon">:</span>
        <span class="block">{{ timeData.seconds }}</span>
      </template>
    </van-count-down>
  </div>
  <div class="stg">
    <ul class="stg-box">
      <li class="stg-item" v-for="(item, index) in hodArr" :key="item.albumId">
        <div class="image">
          <img :src="item.albumCoverPath" alt="" />
        </div>
        <div class="text">{{ item.title }}</div>
      </li>
    </ul>
  </div>
  <!-- 今日热点 -->
  <div class="xrbt">今日热点</div>
  <div class="hod">
    <div class="hod-item" v-for="(item, index) in hodArr" :key="item.albumId">
      <div class="hod-item-lef">
        <div class="icon"><van-icon name="play-circle-o" /></div>
        <img :src="item.albumCoverPath" alt="" />
      </div>
      <div class="hod-item-rig">
        <div class="h4">{{ item.title }}</div>
        <div class="p">
          <span class="span1"
            ><van-icon name="friends-o" />&nbsp;{{ item.anchorName }}</span
          >
        </div>
      </div>
    </div>
  </div>
  <!-- 播客推荐 -->
  <div class="xrbt">播客推荐</div>
  <div class="hod">
    <div class="hod-item" v-for="(item, index) in newArr" :key="item.albumId">
      <div class="hod-item-lef">
        <div class="icon"><van-icon name="play-circle-o" /></div>
        <img :src="'https://imagev2.xmcdn.com/' + item.albumCoverPath" alt="" />
      </div>
      <div class="hod-item-rig">
        <div class="h4">{{ item.albumTitle }}</div>
        <div class="p">
          <span class="span1"
            ><van-icon name="friends-o" />&nbsp;{{
              item.albumUserNickName
            }}</span
          ><span><van-icon name="service-o" />&nbsp;4.04万</span>
        </div>
      </div>
    </div>
  </div>
  <!-- 底部 -->
  <div class="footer">
    <img
      class="img1"
      src="https://imagev2.xmcdn.com/storages/2165-audiofreehighqps/52/6D/GKwRIDoF6Ml9AAESnAEaI6xF.png!magick=webp"
      alt=""
    />
    <div class="logo">
      <img
        class="img2"
        src="https://imagev2.xmcdn.com/storages/72b6-audiofreehighqps/30/CE/GMCoOR8H3gffAAAQWAIAHhDF.png!magick=webp"
        alt=""
      />
    </div>
    <p class="p2">&copy; 2014-2023 喜马拉雅 版本所有</p>
  </div>
  <!--  -->
  <!-- <div class="bbbb"></div> -->
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
// 引入获取 home 小仓库的方法
import { useHomeStore } from "@/store/home";

import { reqNewList, reqHod } from "@/api/home/index";
import { log } from "console";
import { useRouter } from "vue-router";
const pageNum = ref(1);
const pageSize = ref(6);
const newArr = ref<any>([]);
const hodArr = ref<any>([]);
const token = ref<any>();
token.value = localStorage.getItem("TOKEN");
// console.log(123133131,token.value);

//创建路由
let router = useRouter();
onMounted(() => {
  getNewList();
  getHodList();
  if (!token.value) {
    router.push("/xmlogin");
  }
});
// 新人必听去详情回调
const toDetail = (e: any) => {
  router.push({
    name: "Detail",
    params: {id:e},
  });
};
const getNewList = async () => {
  const result = await reqNewList(pageNum.value, pageSize.value);
  // console.log(1231,result);
  newArr.value = result.data.albums;
  console.log(newArr.value);
};
// 获取限时免费
const getHodList = async () => {
  const result = await reqHod();
  // console.log(result);
  hodArr.value = result.data.hotTrack.hotTracks;
  // console.log(hodArr.value,123);
};
</script>

<style scoped lang="less">
.bbbb {
  width: 100%;
  height: 500px;
}
.top {
  width: 100%;
  background: #fff;
  position: fixed;
  top: 0;
  z-index: 99;
  .cen {
    width: 345px;
    height: 30px;
    margin: 15px auto 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    // background: lightpink;
    img {
      width: 116px;
      height: 29px;
    }
    .a {
      width: 68px;
      height: 14px;
      padding: 8px 10px;
      color: #fff;
      line-height: 14px;
      text-align: center;
      background: red;
      border-radius: 30px;
      font-size: 14px;
    }
  }
  .search {
    border-radius: 40px;
  }
}
.cqi {
  width: 100%;
  height: 104px;
}
// 轮播图
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  height: 126px;
  line-height: 126px;
  text-align: center;
  // background-color: #39a9ed;
  img {
    width: 293px;
    height: 126px;
    border-radius: 10px;
  }
}
// 排行榜 分类 听单
.pft {
  width: 308px;
  height: 54px;
  margin: 30px auto 20px;
  // background: lightpink;
  display: flex;
  justify-content: space-around;
  align-items: center;
  div {
    width: 40px;
    height: 100%;
    text-align: center;
    font-size: 12px;
    color: #666;
    img {
      width: 34px;
      height: 34px;
    }
    p {
      margin: 0;
    }
  }
}
// 大图
.big {
  width: 100%;
  height: 81px;
  img {
    width: 100%;
  }
}
// 新人必听
.xrbt {
  width: 300px;
  height: 25px;
  color: #40404c;
  margin: 17px 0px 17px 15px;
  font-size: 18px;
  font-weight: bold;
  display: flex;
}
.new {
  width: 100%;
  height: 312px;
  // background: lightblue;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-evenly;
  .new-item {
    width: 103px;
    height: 156px;
    // background: lightpink;
    .new-item-img {
      width: 103px;
      height: 103px;
      position: relative;
      img {
        width: 103px;
        height: 103px;
      }
      .new-item-text {
        width: 100%;
        height: 20px;
        // background: lightgreen;
        position: absolute;
        bottom: 0;
        color: #fff;
        font-size: 12px;
        line-height: 20px;
      }
    }
    .title {
      font-size: 13px;
      color: #333;
      margin: 0;
      padding: 6px auto 11px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
    }
  }
}
// 限时免费
// 计时器
.colon {
  display: inline-block;
  margin: 0 4px;
  color: #1989fa;
}
.block {
  display: inline-block;
  width: 22px;
  color: #fff;
  font-size: 12px;
  text-align: center;
  background-color: red;
}
.stg {
  width: 100%;
  height: 160px;
  // background: lightpink;
  overflow: hidden;
  overflow: scroll;
  .stg-box {
    // width: 750px;
    height: 160px;
    // background: lightblue;
    display: flex;
    justify-content: space-between;
    .stg-item {
      width: 103px;
      height: 156px;
      margin-right: 7px;
      flex-shrink: 0;
      .image {
        width: 103px;
        height: 103px;
        margin-bottom: 7px;
        img {
          width: 100%;
          height: 100%;
          border-radius: 5px;
        }
      }
      .text {
        font-size: 13px;
        color: #333;
        margin: 0;
        padding: 6px auto 11px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
      }
    }
  }
}
// 今日热点
.hod {
  width: 100%;
  .hod-item {
    width: 345px;
    height: 70px;
    margin: 30px auto;
    // background: lightpink;
    display: flex;
    justify-content: space-between;
    .hod-item-lef {
      width: 70px;
      height: 70px;
      position: relative;
      .icon {
        width: 70px;
        height: 70px;
        position: absolute;
        line-height: 70px;
        text-align: center;
        color: #fff;
      }
      img {
        width: 100%;
        height: 100%;
      }
    }
    .hod-item-rig {
      width: 260px;
      height: 70px;
      .h4 {
        font-size: 16px;
        color: #40404c;
        margin: 0px 0px 5px;
      }
      .p {
        font-size: 12px;
        color: #999;
        .span1 {
          margin-right: 10px;
        }
      }
    }
  }
}
// 播客推荐
// 底部
.footer {
  width: 100;
  height: 180px;
  position: relative;
  .img1 {
    width: 100%;
    height: 180px;
  }
  .logo {
    position: absolute;
    top: 25%;
    left: 50%;
    margin-left: -51px;
    .img2 {
      width: 102px;
    }
  }
  .p2 {
    font-size: 12px;
    text-align: center;
    color: #808080;
    position: absolute;
    top: 45%;
    left: 50%;
    margin-left: -90px;
  }
}

// 清除滚动条
::-webkit-scrollbar {
  width: 0;
  height: 0;
  color: transparent;
}
</style>
